//=====================================================
//
// AutoCompleter.cs
//
// Copyright (C) 2013 Samarjeet Singh
//
//=====================================================
using System;
using System.Collections.Generic;
using FastColoredTextBoxNS;

namespace SS.Ynote.Classic.AutoCompletion
{
    /// <summary>
    /// AutoComplete Manager
    /// </summary>
    public class AutoCompleter
    {
        public static List<AutocompleteItem> BuildKeyWordMenu(IAutoCompleteMenu Menu)
        {
            List<AutocompleteItem> items = new List<AutocompleteItem>();
            foreach (var item in Menu.Keywords)
                items.Add(new AutocompleteItem(item));
            return items;
        }
        /// <summary>
        /// Builds AutoComplete Menu According To IAutoComplete Menu
        /// </summary>
        /// <param name="Menu"></param>
        /// <returns></returns>
        public static List<AutocompleteItem> BuildAutoCompleteMenu(IAutoCompleteMenu Menu)
        {
            List<AutocompleteItem> items = new List<AutocompleteItem>();

            if(Menu.Snippets != null)
                foreach (var item in Menu.Snippets)
                    items.Add(new SnippetAutocompleteItem(item));
            if(Menu.DeclarationSnippets != null)
                foreach (var item in Menu.DeclarationSnippets)
                    items.Add(new DeclarationSnippet(item));
            foreach (var item in Menu.Keywords)
                items.Add(new AutocompleteItem(item));
            if(Menu.Namespaces != null)
                foreach(var item in Menu.Namespaces)
                    items.Add(new ClassAutoCompleteItem(item));

            items.Add(new InsertSpaceSnippet());
            items.Add(new InsertSpaceSnippet(@"^(\w+)([=<>!:]+)(\w+)$"));
            items.Add(new InsertEnterSnippet());

            return items;
            //set as autocomplete source
            //popupMenu.Items.SetAutocompleteItems(items);
        }
        /// <summary>
        /// Returns IAutoComplete Menu From Language
        /// </summary>
        /// <param name="Lang"></param>
        /// <param name="menu"></param>
        /// <returns></returns>
        public static IAutoCompleteMenu FromLanguage(Language Lang, IAutoCompleteMenu menu)
        {
            foreach (Language lang in Enum.GetValues(typeof(Language)))
                if (menu.Name == lang.ToString())
                    return menu;
            return null;
        }
        /// <summary>
        /// Returns Language From AutoCompleteMenu
        /// </summary>
        /// <param name="Lang"></param>
        /// <param name="menu"></param>
        /// <returns></returns>
        public static Language FromAutoCompleteMenu(Language Lang, IAutoCompleteMenu menu)
        {
            foreach (Language lang in Enum.GetValues(typeof(Language)))
                if (lang.ToString() == menu.Name)
                    return lang;
            return Language.Text;
        }
        public static IAutoCompleteMenu AutoComplete(Language lang)
        {
            switch (lang)
            {
                case FastColoredTextBoxNS.Language.Actionscript: return new Java();
                    break;
                case FastColoredTextBoxNS.Language.Assemblyx86: return new ASM();
                    break;
                case FastColoredTextBoxNS.Language.Batch: return new Batch();
                    break;
                case FastColoredTextBoxNS.Language.C: return new CPP();
                    break;
                case FastColoredTextBoxNS.Language.CPP:return new CPP();
                    break;
                case FastColoredTextBoxNS.Language.CSS: return new CSS();
                    break;
                case FastColoredTextBoxNS.Language.CSharp: return new CSharp();
                    break;
                case FastColoredTextBoxNS.Language.D: return new D();
                    break;
                case FastColoredTextBoxNS.Language.Java: return new Java();
                    break;
                case FastColoredTextBoxNS.Language.Lua: return new Lua();
                    break;
                case FastColoredTextBoxNS.Language.ASP: return new HTML();
                    break;
                case FastColoredTextBoxNS.Language.Python: return new Python();
                    break;
                case FastColoredTextBoxNS.Language.Perl: return new Perl();
                    break;
                case FastColoredTextBoxNS.Language.Ruby: return new Ruby();
                    break;
                case FastColoredTextBoxNS.Language.Xml: return new XML();
                    break;
                case FastColoredTextBoxNS.Language.INI: return new General();
                    break;
                case Language.JSON: return new General() as IAutoCompleteMenu;
                    break;
                case FastColoredTextBoxNS.Language.VB: return new VB() as IAutoCompleteMenu;
                    break;
                case FastColoredTextBoxNS.Language.HTML: return new HTML() as IAutoCompleteMenu;
                    break;
                case FastColoredTextBoxNS.Language.Javascript: return new Javascript();
                    break;
                case FastColoredTextBoxNS.Language.SQL: return new SQL();
                    break;
                case FastColoredTextBoxNS.Language.PHP: return new PHP();
                    break;
                case FastColoredTextBoxNS.Language.OpenCL: return new General();
                    break;
                case FastColoredTextBoxNS.Language.Lisp: return new Lisp();
                    break;
                case FastColoredTextBoxNS.Language.FSharp: return new FSharp();
                    break;
                case FastColoredTextBoxNS.Language.Pascal: return new Pascal();
                    break;
                default: return new General();
                    break;
            }
            return null; ;
        }
    }
}
